package com.zhilei.controller;

import com.zhilei.base.BaseInfoProperties;
import com.zhilei.grace.result.GraceJSONResult;
import com.zhilei.pojo.SysParams;
import com.zhilei.pojo.vo.SysParamsVO;
import com.zhilei.service.SysParamsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("sys")
public class SysParamsController extends BaseInfoProperties {

    @Autowired
    private SysParamsService sysParamsService;

    /**
     * 设置最大简历得刷新次数
     *
     * @param maxCounts 简历刷新次数
     * @param version   版本号
     * @return
     */
    @PostMapping("modifyMaxResumeRefreshCounts")
    public GraceJSONResult modifyMaxResumeRefreshCounts(@RequestParam("maxCounts") Integer maxCounts,
                                                        @RequestParam("version") Integer version) {

        if (maxCounts == null || maxCounts < 1) {
            return GraceJSONResult.error();
        }

        sysParamsService.modifyMaxResumeRefreshCounts(maxCounts, version);
        return GraceJSONResult.ok(0);
    }

    /**
     * 查询参数信息
     *
     * @return
     */
    @PostMapping("params")
    public GraceJSONResult params() {

        SysParams sysParams = sysParamsService.getParams();
        SysParamsVO sysParamsVO = new SysParamsVO();
        BeanUtils.copyProperties(sysParams, sysParamsVO);
        sysParamsVO.setVersion(0);
        return GraceJSONResult.ok(sysParamsVO);
    }
}
